﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL;
using Model;

namespace TaoBaoProject.Handlers.QQRelateHandler
{
  /// <summary>
  /// Summary description for AddMenbersHandler
  /// </summary>
  public class AddMenbersHandler : IHttpHandler
  {
    QQRelationBLL qqrelationBLL = new QQRelationBLL();
    QQRelation qqrelationModel = new QQRelation();
    public void ProcessRequest(HttpContext context)
    {
      context.Response.ContentType = "text/plain";
      qqrelationModel.MainQQ = context.Request["MainQQ"].ToString();
      qqrelationModel.QQ = context.Request["QQ"].ToString();

      var dtExistQQ = qqrelationBLL.IsSameQQ(qqrelationModel.MainQQ, qqrelationModel.QQ);
      if (dtExistQQ.Rows.Count == 0)
      {
        qqrelationModel.CreateTime = DateTime.Now.ToString();
        qqrelationBLL.AddQQRelation(qqrelationModel);
        string returnValue = "{MainQQ:'" + qqrelationModel.MainQQ + "',QQ:'" + qqrelationModel.QQ + "',CreateTime:'" + qqrelationModel.CreateTime + "'}";
        context.Response.Write(returnValue);
      }
      else
      {
        context.Response.Write("{Repeater:'1'}");
      }
    }

    public bool IsReusable
    {
      get
      {
        return false;
      }
    }
  }
}